<template>
  <div class="homePage">
    <div class="homePageHeader">
      <h2>欢迎来到茶叶商城!</h2>
    </div>
    <searchTea></searchTea>
    <!-- 商品展示区 -->
    <SearchProduct></SearchProduct>
    <div class="hotSale"></div>
    <!-- 图表展示区 -->
    <div class="chart">
      <div class="bar">
        <bar :bar="bar" v-if="flag"></bar>
      </div>
      <div class="pie">
        <pie :pie="pie" v-if="flag"></pie>
      </div>
    </div>
  </div>
</template>

<script>
import bar from "../../components/homePage/chart.vue";
import pie from "../../components/homePage/pie.vue";
import searchTea from "../../components/homePage/searchTea.vue";
import SearchProduct from "../../components/homePage/SearchProduct.vue";
import { getRequest } from "../../util/request";
export default {
  name: "homePage",
  components: {
    bar,
    pie,
    searchTea,
    SearchProduct,
  },
  data() {
    return {
      //设置属性
      //#region
      /* swiperOption: {
                //显示分页
                pagination: {
                el: '.swiper-pagination',
                clickable: true //允许分页点击跳转
                },
                //设置点击箭头
                navigation: {
                nextEl: '.swiper-button-next', 
                prevEl: '.swiper-button-prev'
                },
                //自动轮播
                autoplay: {
                delay: 2000
                },
                //开启循环模式
                loop: true,
                //开启鼠标滚轮控制Swiper切换
                mousewheel: true
            } */
      //#endregion
      bar: [],
      pie: [],
      nameObj: [],
      flag: false,
    };
  },
  created() {
    //查询所有订单数据

    let orderResult = getRequest("order/selOrderTea", "");
    orderResult.then(
      (response) => {
        // console.log("Object.keys", response.data);
        this.bar = Object.values(response.data);
        this.pie = [];
        // this.nameObj = Object.keys(response.data);
        //将英文茶名转化为中文茶名
        let teaData = Object.entries(response.data).map((item) => {
          if (item[0] === "white") {
            item[0] = "白茶";
          } else if (item[0] === "oolong") {
            item[0] = "乌龙茶";
          } else if (item[0] === "black") {
            item[0] = "红茶";
          } else if (item[0] === "dark") {
            item[0] = "黑茶";
          } else if (item[0] === "oolong") {
            item[0] = "乌龙茶";
          } else if (item[0] === "yellow") {
            item[0] = "黄茶";
          } else {
            item[0] = "绿茶";
          }
          return item;
        });
        //添加茶叶对象
        teaData.forEach((item) => {
          this.pie.push({ value: item[1], name: item[0] });
        });
        this.flag = true;
      },
      (reason) => {
        console.log(reason);
      }
    );
  },
  mounted() {
    /* setTimeout(() => {
      console.log("this.bar", this.bar);
    }, 100); */
    // console.log("this.$router", this.$route);
  },
};
</script>

<style scoped lang='less'>
.homePage {
  width: 100%;
  min-height: 800px;
  background-color: white;
  position: relative;
  // text-align: center;
  .homePageHeader {
    width: 100%;
    height: 80px;
    line-height: 80px;
    border-bottom: rgb(143, 142, 140);

    h2 {
      float: left;
      margin-top: -10px;
      margin-left: 20px;
      color: rgb(48, 214, 7);
    }
  }

  .hotSale {
    width: 100%;
    margin: 15px 10px;
  }
  .chart {
    margin-top: 50px;
    display: flex;
    justify-content: space-around;
  }
  /* .homePageSwiper{
        // width: 90%;
        margin: 20px;
        padding-bottom: 20px;
        margin-top: -30px;

        // margin-left: -300px;
        // position: absolute;
        // left: 0;
        .outerSwiper{
            width: 100%;
             .swiper-slide {
            width: 100%;
            height: 500px;
            line-height:500px;
            font-size: 50px;
            text-align: center;
            background-color: rgb(187, 179, 179);
            img{
                width: 100%;
                height: 100%;
            }
        }
        }
       
    } */
}
</style>